package com.smart.wap.service;


import com.smart.manager.product.entities.enums.CameraDirection;
import com.smart.manager.product.entities.models.BasicCameraDetail;
import com.smart.manager.product.entities.models.query.QBasicCameraDetail;
import com.smart.manager.product.repository.BasicCameraDetailRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
@RequiredArgsConstructor
@Slf4j
public class OpenService {

    private final BasicCameraDetailRepository basicCameraDetailRepository;

    /**
     * 获取实景牧场
     * @param kind 获取实景牧场
     * @return {@link List}<{@link String}>
     */
    public List<String> getOpenCamera(String kind){
        List<BasicCameraDetail> details = new QBasicCameraDetail().videoLocation.eq(kind).status.eq(1).isEncrypt.eq(0).cameraDirection.eq(CameraDirection.EXTERIOR).setMaxRows(5).findList();
        ArrayList<String> arrayList = new ArrayList<>();
        for (BasicCameraDetail detail : details) {
            arrayList.add( basicCameraDetailRepository.getCameraUrl(detail, false));
        }
        return arrayList;
    }

    public List<String> getOpenProcessingCamera(){
        List<BasicCameraDetail> details = new QBasicCameraDetail().status.eq(1).isEncrypt.eq(0).cameraDirection.eq(CameraDirection.PROCESSING).findList();
        ArrayList<String> arrayList = new ArrayList<>();
        for (BasicCameraDetail detail : details) {
            arrayList.add( basicCameraDetailRepository.getCameraUrl(detail, false));
        }
        return arrayList;
    }


    public List<String> getOpenSanCameraLive(){
        List<BasicCameraDetail> details = new QBasicCameraDetail().status.eq(1).isEncrypt.eq(0).cameraDirection.eq(CameraDirection.ANNOUNCEMENT).setMaxRows(5).findList();
        ArrayList<String> arrayList = new ArrayList<>();
        for (BasicCameraDetail detail : details) {
            arrayList.add( basicCameraDetailRepository.getLiveHtml(detail));
        }
        return arrayList;
    }

    public List<String> getOpenCameraHtml(){
        List<BasicCameraDetail> details = new QBasicCameraDetail().status.eq(1).isEncrypt.eq(0).cameraDirection.in(CameraDirection.FORMER,CameraDirection.AFTER).setMaxRows(5).findList();
        ArrayList<String> arrayList = new ArrayList<>();
        for (BasicCameraDetail detail : details) {
            arrayList.add( basicCameraDetailRepository.getLiveHtml(detail));
        }
        return arrayList;
    }
    public List<String> getOpenCameraLive(){
        List<BasicCameraDetail> details = new QBasicCameraDetail().status.eq(1).isEncrypt.eq(0).cameraDirection.in(CameraDirection.FORMER,CameraDirection.AFTER).setMaxRows(5).findList();
        ArrayList<String> arrayList = new ArrayList<>();
        for (BasicCameraDetail detail : details) {
            arrayList.add( basicCameraDetailRepository.getLive(detail));
        }
        return arrayList;
    }
}
